package com.flower.controller;

import com.flower.model.dto.SupplierDTO;
import com.flower.model.dto.SupplierPageQueryDTO;
import com.flower.result.PageResult;
import com.flower.result.Result;
import com.flower.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName SupplierController
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/13 16:54
 *@Version 1.0
 */
@Api("供应商")
@RestController
@RequestMapping("/supplier")
@Slf4j
public class SupplierController {
    @Autowired
    private SupplierService supplierService;
    @GetMapping("/page")
    @ApiOperation("分页查询供应商信息")
    public Result<PageResult> pageQuery(SupplierPageQueryDTO supplierPageQueryDTO) {
        log.info("分页查询供应商信息");
        PageResult pageResult = supplierService.pageQuery(supplierPageQueryDTO);
        return Result.success(pageResult);
    }
    @PostMapping
    @ApiOperation("添加/修改供应商信息")
    public Result add(@RequestBody SupplierDTO supplierDTO) {
        log.info("添加/修改供应商信息");
        supplierService.addOrUpdate(supplierDTO);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除供应商信息")
    public Result delete(@PathVariable Integer id) {
        log.info("删除供应商信息");
        supplierService.deleteSupplier(id);
        return Result.success();
    }
    @PostMapping("/del/batch")
    @ApiOperation("批量删除供应商信息")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        log.info("批量删除供应商信息");
        supplierService.deleteSupplierBatch(ids);
        return Result.success();
    }

    @GetMapping("/")
    @ApiOperation("查询所有供应商信息")
    public Result<List<SupplierDTO>> list() {
        log.info("查询所有供应商信息");
        List<SupplierDTO> list = supplierService.list();
        return Result.success(list);
    }

}
